<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>

    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSave">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { assignRoles } from '@/api/employees'
import { getUserDetailById } from '@/api/user'
import { getRoles } from '@/api/setting'
export default {
  props: {
    employeeId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  // created() {
  //   this.loadRoles()
  // },
  methods: {
    async loadRoles() {
      try {
        const res = await getRoles(1, 100)
        console.log(res)
        this.list = res.data.rows
        const info = await getUserDetailById(this.employeeId)
        console.log(info)
        // 保存这个员工当前的已经有的角色
        this.roleIds = info.data.roleIds
      } catch (err) {
        console.log(err)
      }
    },
    closeDialog() {
      this.$emit('close')
    },
    async hSave() {
      const res = await assignRoles({ id: this.employeeId, roleIds: this.roleIds })
      console.log(res)
      this.$emit('AssignRole')
    }
  }
}
</script>
